package GUI;

import Payment.PaySMS;
import Payment.Cash;
import Payment.CreditCard;
import javax.swing.JOptionPane;

/**
 * Class for the PayDA panel in GUI
 */
public class PayDA extends javax.swing.JPanel {
    tvmGUI master;
    WelcomeDA WelcomeDAClass;
    CartDA CartDAClass;
    CashDA CashDAClass;
    CardDA CardDAClass;
    SMSDA SMSDAClass;
    
    /**
     * Custom constructor
     * @param tvmGUI Reference to {@link tvmGUI}.
     */
    public PayDA(tvmGUI tvmGUI) {
        master = tvmGUI;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabPayDAInfo = new javax.swing.JLabel();
        LabPayDATime = new javax.swing.JLabel();
        LabPayDATitle = new javax.swing.JLabel();
        LabPayDAInstruct = new javax.swing.JLabel();
        ButPayDACash = new javax.swing.JButton();
        ButPayDACard = new javax.swing.JButton();
        ButPayDASMS = new javax.swing.JButton();
        ButPayDAClear = new javax.swing.JButton();
        ButPayDABack = new javax.swing.JButton();
        ButPayDAHelp = new javax.swing.JButton();
        BackgroundPIC = new javax.swing.JLabel();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        LabPayDAInfo.setText(" ");
        add(LabPayDAInfo, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 297, -1));

        LabPayDATime.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabPayDATime.setText("  ");
        add(LabPayDATime, new org.netbeans.lib.awtextra.AbsoluteConstraints(477, 11, 313, -1));

        LabPayDATitle.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        LabPayDATitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("Interface/Bundle"); // NOI18N
        LabPayDATitle.setText(bundle.getString("BETALING")); // NOI18N
        add(LabPayDATitle, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 69, 199, -1));

        LabPayDAInstruct.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabPayDAInstruct.setText(bundle.getString("VÆLG ØNSKET BETALINGSFORM.")); // NOI18N
        add(LabPayDAInstruct, new org.netbeans.lib.awtextra.AbsoluteConstraints(246, 109, 307, -1));

        ButPayDACash.setText(bundle.getString("KONTANT")); // NOI18N
        ButPayDACash.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPayDACashActionPerformed(evt);
            }
        });
        add(ButPayDACash, new org.netbeans.lib.awtextra.AbsoluteConstraints(327, 162, 144, 66));

        ButPayDACard.setText(bundle.getString("BETALINGSKORT")); // NOI18N
        ButPayDACard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPayDACardActionPerformed(evt);
            }
        });
        add(ButPayDACard, new org.netbeans.lib.awtextra.AbsoluteConstraints(327, 269, 144, 66));

        ButPayDASMS.setText(bundle.getString("SMS")); // NOI18N
        ButPayDASMS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPayDASMSActionPerformed(evt);
            }
        });
        add(ButPayDASMS, new org.netbeans.lib.awtextra.AbsoluteConstraints(327, 378, 144, 66));

        ButPayDAClear.setText(bundle.getString("AFBRYD")); // NOI18N
        ButPayDAClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPayDAClearActionPerformed(evt);
            }
        });
        add(ButPayDAClear, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 549, 100, 40));

        ButPayDABack.setText(bundle.getString("TILBAGE")); // NOI18N
        ButPayDABack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPayDABackActionPerformed(evt);
            }
        });
        add(ButPayDABack, new org.netbeans.lib.awtextra.AbsoluteConstraints(491, 549, 101, 40));

        ButPayDAHelp.setText(bundle.getString("?")); // NOI18N
        ButPayDAHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPayDAHelpActionPerformed(evt);
            }
        });
        add(ButPayDAHelp, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 549, 50, 40));

        BackgroundPIC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/BackgroundGUI.png"))); // NOI18N
        add(BackgroundPIC, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 810, 600));
    }// </editor-fold>//GEN-END:initComponents
   
    /**
     * Sets references to other panels
     * @param refWelcomeDA Reference to WelcomeDA panel.
     * @param refCartDA Reference to CartDA panel. 
     * @param refCashDA Reference to CashDA panel.
     * @param refCardDA Reference to CardDA panel.
     * @param refSMSDA Reference to SMSDA panel.
     */
    public void setReferences(WelcomeDA refWelcomeDA, CartDA refCartDA
            , CashDA refCashDA, CardDA refCardDA, SMSDA refSMSDA) {
        WelcomeDAClass = refWelcomeDA;
        CartDAClass = refCartDA;
        CashDAClass = refCashDA;
        CardDAClass = refCardDA;
        SMSDAClass = refSMSDA;
    }
    
    private void ButPayDACashActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPayDACashActionPerformed
        // New instance of Cash simulation
        master.PY = new Cash(master.SB.getTotalPrice());
        // Set labels
        CashDAClass.LabCashDAInfo.setText(WelcomeDA.languageBundle
                .getString("MASKIN ID: ")+master.hardID+WelcomeDA
                        .languageBundle.getString("ZONE: ")+master.startZone);
        CashDAClass.LabCashDAMissing.setText(WelcomeDA.languageBundle
                .getString("MANGLER: ")+master.SB.getTotalPrice()+WelcomeDA
                        .languageBundle.getString("DKK"));
        // Go to next window
        master.ChangePanel(CashDAClass);
    }//GEN-LAST:event_ButPayDACashActionPerformed

    private void ButPayDACardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPayDACardActionPerformed
        // Set lables
        CardDAClass.LabCardDAInfo.setText(WelcomeDA.languageBundle
                .getString("MASKIN ID: ")+master.hardID+WelcomeDA.languageBundle
                        .getString("ZONE: ")+master.startZone);
        CardDAClass.LabCardDATotal.setText(WelcomeDA.languageBundle
                .getString("TOTAL PRIS: ")+master.SB.getTotalPrice()+WelcomeDA
                        .languageBundle.getString("DKK"));
        String wrongPin = "1337";    // A pin to force simulation of failed pin
        // Make Creditcard instance
        master.PY = new CreditCard(wrongPin);
        // Move to next window
        master.ChangePanel(CardDAClass);
    }//GEN-LAST:event_ButPayDACardActionPerformed

    private void ButPayDASMSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPayDASMSActionPerformed
        // Set lables
        SMSDAClass.LabSMSDAInfo.setText(WelcomeDA.languageBundle
                .getString("MASKIN ID: ")+master.hardID+WelcomeDA
                        .languageBundle.getString("ZONE: ")+master.startZone);
        SMSDAClass.LabSMSDATotal.setText(WelcomeDA.languageBundle
                .getString("TOTAL PRIS: ")+master.SB.getTotalPrice()
                +WelcomeDA.languageBundle.getString("DKK"));
        String failedNUM = "88888888";  // number to force error-simulation
        // Make SMS instance
        master.PY = new PaySMS(failedNUM);
        // Move to next window
        master.ChangePanel(SMSDAClass);
    }//GEN-LAST:event_ButPayDASMSActionPerformed

    private void ButPayDAClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPayDAClearActionPerformed
        // Clear content of cart-array, list-array, and list
        master.CartDAClass.ListCartDATicketList.removeAll();
        master.CartContent.clear();
        master.SB.clearCart();
        // Reset selectionscreen's inputs
        master.resetSelectionScreen();
        // Go back to welcomeing screen
        master.ChangePanel(WelcomeDAClass);
    }//GEN-LAST:event_ButPayDAClearActionPerformed

    private void ButPayDABackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPayDABackActionPerformed
        // Go back to previous window
        master.ChangePanel(CartDAClass);
    }//GEN-LAST:event_ButPayDABackActionPerformed

    private void ButPayDAHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPayDAHelpActionPerformed
        JOptionPane.showMessageDialog(this,
            WelcomeDA.languageBundle.getString("FOR HJÆLP RING XX XX XX XX")
            + WelcomeDA.languageBundle
                    .getString("FOR TEKNISK ASSISTANCE RING XX XX XX XX")
            + WelcomeDA.languageBundle.getString("HUSK AT OPLYSE MASKINENS ID, SOM KAN FINDES I ØVRE VENSTRE HJØRNE.")
            + "\n"
            + WelcomeDA.languageBundle.getString("BLUEJ TRAKFIKSELSKAB")
                , WelcomeDA.languageBundle.getString("HJÆLP OG TEKNISK SUPPORT")
            , JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_ButPayDAHelpActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JLabel BackgroundPIC;
    public javax.swing.JButton ButPayDABack;
    public javax.swing.JButton ButPayDACard;
    public javax.swing.JButton ButPayDACash;
    public javax.swing.JButton ButPayDAClear;
    public javax.swing.JButton ButPayDAHelp;
    public javax.swing.JButton ButPayDASMS;
    public javax.swing.JLabel LabPayDAInfo;
    public javax.swing.JLabel LabPayDAInstruct;
    public javax.swing.JLabel LabPayDATime;
    public javax.swing.JLabel LabPayDATitle;
    // End of variables declaration//GEN-END:variables
}
